package com.selftest.config;

import com.selftest.web.http.JSONHttpMessageConverter;
import com.selftest.web.interceptor.HandlerHolder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {

    /**
     * 实例化请求 handler
     * @return
     */
    @Bean(name = "requestHandlerHolder")
    public HandlerHolder requestHandlerHolder(){
        return new HandlerHolder();
    }

    /**
     * 返回体消息过滤 Bean
     * @return
     */
    @Bean
    public JSONHttpMessageConverter jsonHttpMessageConverter(){
        return new JSONHttpMessageConverter();
    }

    /**
     * 注册请求拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(requestHandlerHolder());
    }
}
